#include "lsp_server.h"
#include <iostream>
#include <string>

using namespace std;

int main()
{
	lsp_server* lsp;
	lsp = lsp_server_create(9988);
	if(lsp == NULL)
	{
		cout << "Error creating server.";
	}
	else
	{
		cout << "Server running." << endl;
		while(true)
		{
			char* pld;
			pld = (char*) malloc(1024);
			uint32_t connid = 0;
			int lth = lsp_server_read(lsp, (uint8_t*) pld, &connid);
			if(lth <= 0)
			{
				cout << "Failure to read. lth = " << lth << endl;
			}
			else
			{
				cout << "Server read: " << endl << string(pld) << endl;
				if(!lsp_server_write(lsp, pld, lth, (uint32_t) connid))
				{
					cout << "Server failed write." << endl;
				}
			}
			//IMPORTANT! Don't forget to delete pld!
			delete pld;
		}
	}
	return 0;
}
